import random

def generate_grid(m, n, land_probability=0.3):
    """生成随机网格数据"""
    return [
        [
            "1" if random.random() < land_probability else "0"
            for _ in range(n)
        ]
        for _ in range(m)
    ]

def write_grid_to_file(grid, filename):
    """将网格数据写入文件"""
    with open(filename, 'w') as f:
        for row in grid:
            f.write(' '.join(row) + '\n')

if __name__ == "__main__":
    # 生成一个10x10的测试网格
    test_grid = generate_grid(10, 10)
    write_grid_to_file(test_grid, "test_grid.txt")
    print("测试数据已生成到 test_grid.txt")    